package com.hc.server.user.service.impl;

import com.hc.server.user.domain.vo.response.user.UserInfoResp;
import com.hc.server.user.dao.UserBackpackDao;
import com.hc.server.user.domain.entity.User;
import com.hc.server.user.domain.enums.ItemEnum;
import com.hc.server.user.service.UserService;
import com.hc.server.user.service.adapter.UserAdapter;
import com.hc.server.user.service.cache.UserCache;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by wdj on 2024/10/15
 */

@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Autowired
    private UserCache userCache;
    @Autowired
    private UserBackpackDao userBackpackDao;

    @Override
    public UserInfoResp getUserInfo(Long uid) {
        User userInfo = userCache.getUserInfo(uid);
        Integer countByValidItemId = userBackpackDao.getCountByValidItemId(uid, ItemEnum.MODIFY_NAME_CARD.getId());
        log.info("获取用户信息:{}", userInfo);
        return UserAdapter.buildUserInfoResp(userInfo, countByValidItemId);
    }
}
